package com.example.qxfw.rcyw.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.qxfw.common.entity.yj.WaterWarnMoniInfo;
import com.example.qxfw.rcyw.mapper.WaterWarnMoniInfoMapper;
import com.example.qxfw.rcyw.service.WaterWarnMoniInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

@Service
public class WaterWarnMoniInfoServiceImpl implements WaterWarnMoniInfoService {

    @Autowired
    private WaterWarnMoniInfoMapper waterWarnMoniInfoMapper;

    @Override
    public List<WaterWarnMoniInfo> getWaterWarnMonitor(Integer waterAutoHour) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - waterAutoHour);
        Timestamp obeservetime = Timestamp.valueOf(sdf.format(calendar.getTime()));
        LambdaQueryWrapper<WaterWarnMoniInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.gt(WaterWarnMoniInfo::getObeservetime,obeservetime).eq(WaterWarnMoniInfo::getIsremoved,0);
        List<WaterWarnMoniInfo> waterWarnMoniInfos = waterWarnMoniInfoMapper.selectList(queryWrapper);
        return waterWarnMoniInfos;
    }

    @Override
    public Integer updateWaterMonitor(WaterWarnMoniInfo waterWarnMoniInfo) {
        return waterWarnMoniInfoMapper.updateById(waterWarnMoniInfo);
    }
}
